package dao

import (
	"github.com/douyu/jupiter/pkg/store/gorm"
	"jupiter-demo/internal/app/model/db"
	"time"
)

type userinfo struct {
	DB *gorm.DB
}

// InitUser ...
func InitUserinfo(db *gorm.DB) *userinfo {
	u := &userinfo{
		DB: db,
	}
	return u
}

func (u *userinfo) GetUserInfoByID(id int) (userData db.UserInfo) {
	u.DB.Where("id=?", id).Find(&userData)
	return
}

func (u *userinfo)GetLoginTime(timerstart,timeend time.Time) (userinfo db.UserInfo,err error) {
	userinfo = db.UserInfo{}
	err = u.DB.Where("last_login_time >= ? and last_login_time <= ? and is_delete = 0 and user_type = 2", timerstart,timeend).Find(&userinfo).Error
	return
}

func (u *userinfo)GetLoginTimeNum(timerstart,timeend time.Time) (count int,err error) {
	err = u.DB.Model(&db.UserInfo{}).Where("last_login_time >= ? and last_login_time <= ? and is_delete = 0 and user_type = 2", timerstart,timeend).Count(&count).Error
	if err != nil{
		return  0,err
	}
	return count ,nil
}
